package Review2;

public class Test18 {
    public boolean hasSubTree(BinaryTreeNode root1,BinaryTreeNode root2){
    	if(root1==null){
    		return false;
    	}
    	if(root2==null){
    		return true;
    	}
    	boolean result = false;
    	if(root1.value==root2.value){
    		result= doesTree1HasTree2(root1,root2);
    	}
    	if(!result){
    		result = hasSubTree(root1.left, root2);
    	}
    	if(!result){
    		result = hasSubTree(root1.right, root2);
    	}
    	return result;
    }
    public boolean doesTree1HasTree2(BinaryTreeNode root1,BinaryTreeNode root2){
    	if(root1==null){
    		return false;
    	}
    	if(root2==null){
    		return true;
    	}
    	if(root1.value!=root2.value){
    		return false;
    	}
    	return doesTree1HasTree2(root1.left, root2.left)&&doesTree1HasTree2(root1.right, root2.right);
    }
}
